#!/bin/bash
###############################################################
######### Result 0:OK  1:WARN   2:ERROR   ##################### 
###############################################################


CPU_VAL=$1
DISK_HIGH_VAL=$2
DISK_LOW_VAL=$3

CPU_USAGE=`grep 'cpu ' /proc/stat | awk '{usage=($2+$3+$4)*100/($2+$3+$4+$5)} END {print usage }'`
#echo "CPU_USAGE:"$CPU_USAGE
CPU_USAGE_RSULT=false

DISK_USAGE=`df -hl | awk '$6 ~ /^\/$/ {print $4}' | sed 's/G//g'`
#echo "DISK_USAGE:"$DISK_USAGE
DISK_USAGE_RESULT=false

if [ $(echo "$CPU_USAGE < $CPU_VAL" | bc) -eq 1 ]; then
    CPU_USAGE_RSULT=0
    #   echo "The CPU is available!!"
else
    CPU_USAGE_RSULT=1
    #echo "The CPU is warn"
fi

if [ $DISK_USAGE -gt $DISK_HIGH_VAL ]; then
    DISK_USAGE_RESULT=0
    #echo "The Disk is available!!"
elif [ $DISK_USAGE -lt $DISK_LOW_VAL ]; then
    DISK_USAGE_RESULT=2
    #echo "The Disk is error!!"
else
     DISK_USAGE_RESULT=1
    #echo "The Disk is warn!!"
fi


if [ $DISK_USAGE_RESULT == '2' ]; then
    #echo "node checking error !"
    exit 2
elif [ $CPU_USAGE_RSULT == '1' -o $DISK_USAGE_RESULT == '1' ]; then
    #echo "node checking warn !"
    exit 1
else
    #echo "node checking normal"
    exit 0
fi